package com.uuah.server.config.spring.handlers;

import com.uuah.config.QueueProfile;
import com.uuah.config.object.PrototypeObjectFactory;
import com.uuah.server.channel.DefaultChannel;
import com.uuah.server.component.PooledJavaComponent;
import com.uuah.server.component.model.seda.SedaService;
import com.uuah.server.config.Constants;
import com.uuah.server.config.spring.factories.UuahEndpointFactoryBean;
import com.uuah.server.config.spring.parsers.collection.ChildMapDefinitionParser;
import com.uuah.server.config.spring.parsers.collection.ChildMapEntryDefinitionParser;
import com.uuah.server.config.spring.parsers.generic.ChildDefinitionParser;
import com.uuah.server.config.spring.parsers.generic.ParentDefinitionParser;
import com.uuah.server.config.spring.parsers.specific.ComponentDelegatingDefinitionParser;
import com.uuah.server.config.spring.parsers.specific.ConfigurationDefinitionParser;
import com.uuah.server.config.spring.parsers.specific.DefaultThreadingProfileDefinitionParser;
import com.uuah.server.config.spring.parsers.specific.GlobalPropertyDefinitionParser;
import com.uuah.server.config.spring.parsers.specific.ModelDefinitionParser;
import com.uuah.server.config.spring.parsers.specific.ObjectFactoryDefinitionParser;
import com.uuah.server.config.spring.parsers.specific.PoolingProfileDefinitionParser;
import com.uuah.server.config.spring.parsers.specific.ServiceDefinitionParser;
import com.uuah.server.config.spring.parsers.specific.ThreadingProfileDefinitionParser;
import com.uuah.server.config.spring.parsers.specific.TransformerRefDefinitionParser;
import com.uuah.server.config.spring.parsers.specific.endpoint.GenericEndpointDefinitionParser;
import com.uuah.server.util.spring.SpringBeanLookup;
import com.uuah.server.util.store.InMemoryObjectStore;
import com.uuah.server.util.store.TextFileObjectStore;

public class UuahNamespaceHandler extends AbstractUuahNamespaceHandler {

	public void init() {
		registerIgnoredElement("uuah");
		registerIgnoredElement("description");

		registerBeanDefinitionParser("configuration",
				new ConfigurationDefinitionParser());
		registerBeanDefinitionParser("global-property",
				new GlobalPropertyDefinitionParser());
		registerBeanDefinitionParser("default-threading-profile",
				new DefaultThreadingProfileDefinitionParser(
						Constants.OBJECT_DEFAULT_THREADING_PROFILE));
		registerBeanDefinitionParser(
				"default-dispatcher-threading-profile",
				new DefaultThreadingProfileDefinitionParser(
						Constants.OBJECT_DEFAULT_MESSAGE_DISPATCHER_THREADING_PROFILE));
		registerBeanDefinitionParser(
				"default-receiver-threading-profile",
				new DefaultThreadingProfileDefinitionParser(
						Constants.OBJECT_DEFAULT_MESSAGE_RECEIVER_THREADING_PROFILE));
		registerBeanDefinitionParser("default-service-threading-profile",
				new DefaultThreadingProfileDefinitionParser(
						Constants.OBJECT_DEFAULT_SERVICE_THREADING_PROFILE));
		registerBeanDefinitionParser("threading-profile",
				new ThreadingProfileDefinitionParser("threadingProfile",
						Constants.OBJECT_DEFAULT_SERVICE_THREADING_PROFILE));

		registerBeanDefinitionParser("pooling-profile",
				new PoolingProfileDefinitionParser());
		registerBeanDefinitionParser("queue-profile",
				new ChildDefinitionParser("queueProfile", QueueProfile.class));

		registerBeanDefinitionParser(
				"dispatcher-threading-profile",
				new ThreadingProfileDefinitionParser(
						"dispatcherThreadingProfile",
						Constants.OBJECT_DEFAULT_MESSAGE_DISPATCHER_THREADING_PROFILE));
		registerBeanDefinitionParser(
				"receiver-threading-profile",
				new ThreadingProfileDefinitionParser(
						"receiverThreadingProfile",
						Constants.OBJECT_DEFAULT_MESSAGE_RECEIVER_THREADING_PROFILE));

		// Transformer elements
		registerBeanDefinitionParser("transformers",
				new ParentDefinitionParser());

		registerUuahBeanDefinitionParser("response-transformers",
				new ParentDefinitionParser());
		registerBeanDefinitionParser("transformer",
				new TransformerRefDefinitionParser());

		// Endpoint elements
		registerBeanDefinitionParser("request-endpoint",
				new GenericEndpointDefinitionParser(
						UuahEndpointFactoryBean.class));

		// Models
		registerBeanDefinitionParser("model", new ModelDefinitionParser());

		// Services
		registerBeanDefinitionParser("service", new ServiceDefinitionParser(
				SedaService.class));

		// Components
		registerBeanDefinitionParser("pooled-component",
				new ComponentDelegatingDefinitionParser(
						PooledJavaComponent.class));

		// Object Factories
		registerBeanDefinitionParser("prototype-object",
				new ObjectFactoryDefinitionParser(PrototypeObjectFactory.class,
						"objectFactory"));
		registerBeanDefinitionParser("spring-object",
				new ObjectFactoryDefinitionParser(SpringBeanLookup.class,
						"objectFactory"));

		// Stores
		registerBeanDefinitionParser("in-memory-store",
				new ChildDefinitionParser("store", InMemoryObjectStore.class));
		registerBeanDefinitionParser("simple-text-file-store",
				new ChildDefinitionParser("store", TextFileObjectStore.class));

		// Channels
		registerBeanDefinitionParser("request", new ChildDefinitionParser(
				"requestChannel", DefaultChannel.class));

		// Utils / Standard Types
		registerUuahBeanDefinitionParser("properties",
				new ChildMapDefinitionParser("properties")).addCollection(
				"properties");
		registerUuahBeanDefinitionParser("property",
				new ChildMapEntryDefinitionParser("properties")).addCollection(
				"properties");
	}

}
